package com.yiji.fintech.musfinance.common.strategy.gateway;

import com.acooly.core.utils.enums.ResultStatus;
import com.acooly.core.utils.mapper.BeanCopier;
import com.yiji.fintech.musfinance.base.facade.GatewayOrderFacade;
import com.yiji.fintech.musfinance.base.facade.GatewayResultFacade;
import com.yiji.fintech.musfinance.center.base.result.ResultFacade;
import com.yiji.fintech.musfinance.common.domain.DepositBackDomain;
import com.yiji.fintech.musfinance.common.domain.base.BaseDomain;
import com.yiji.fintech.musfinance.common.factory.gateway.DepositBackFactory;
import com.yiji.fintech.musfinance.common.strategy.base.AbstractSendGateWayBaseStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 充退发送网关策略
 * Created by ouwen@yiji.com} on 2017/10/16.
 */
@Service
public class SendGateWayDepositBackStrategy extends AbstractSendGateWayBaseStrategy {

    @Autowired
    private DepositBackFactory depositBackFactory;

    @Override
    protected GatewayOrderFacade converter(BaseDomain domain) {
        return depositBackFactory.factory(domain);
    }

    @Override
    protected GatewayResultFacade send(BaseDomain domain) {
        //TODO
        //网关 orderGateWay
        GatewayResultFacade resultFacade = new GatewayResultFacade();
        resultFacade.setStatus(ResultStatus.processing);
        resultFacade.setCode(ResultStatus.processing.getCode());
        resultFacade.setDetail("mock网关充退处理成功");
        resultFacade.setPartnerId(orderGateWay.getPartnerId());
        resultFacade.setMerchOrderNo(orderGateWay.getMerchOrderNo());
        resultFacade.setBizOrderNo(orderGateWay.getBizOrderNo());
        resultFacade.setGid(orderGateWay.getGid());
        //调用网关接口
        return resultFacade;
    }

    @Override
    protected void result(BaseDomain domain, ResultFacade result) {
        //TODO
        BeanCopier.copy(resultGateWay,result,BeanCopier.CopyStrategy.IGNORE_NULL, BeanCopier.NoMatchingRule.IGNORE,null);
        DepositBackDomain depositBackDomain = (DepositBackDomain)domain;
        BeanCopier.copy(resultGateWay,depositBackDomain,BeanCopier.CopyStrategy.IGNORE_NULL, BeanCopier.NoMatchingRule.IGNORE,null);
    }
}
